#ifndef AUDIOPLAYER_H
#define AUDIOPLAYER_H

#include <QObject>
#include <phonon/MediaObject>
#include <phonon/AudioOutput>
#include <QPropertyAnimation>

class AudioPlayer : public QObject
{
    Q_OBJECT
public:
    explicit AudioPlayer(QObject *parent = 0);

signals:

public slots:
    /**
     * @brief clear
     *Clear queue, pause
     */
    void clear();
    /**
     * @brief addMusic
     * @param media
     *Add media to queue
     */
    void addMusic(QVector<Phonon::MediaSource> &media);
    /**
     * @brief play
     *Volume->val
     *Play queue
     */
    void play();
    /**
     * @brief pause
     *Volume->0, pause
     */
    void pause();
    /**
     * @brief setVolume
     * @param value
     */
    void setVolume(qreal value);
    /**
     * @brief setRingEnable
     * @param enable
     *Play never end
     */
    void setRingEnable(bool enable);

private slots:
    void stateChanged(Phonon::State oldState, Phonon::State newState);
    void volumeAnimationFinish();
    void finished();

private:
    void volumeUp();
    void volumeDown();

    bool m_ringEnable;
    Phonon::MediaObject *m_mediaObject;
    Phonon::AudioOutput *m_audioOutput;
    QVector<Phonon::MediaSource> m_mediaQueue;
    qreal m_volume;
    QPropertyAnimation *m_volumeAnimation;
};

#endif // AUDIOPLAYER_H
